package applet;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;
import javax.swing.UIManager;

public class TestFrame extends JFrame {

	JSpinner yearSpinner;
	private ImageIcon icon;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	    try {
	        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
	            public void run() {
	        		UIManager.put("Spinner.arrowButtonSize", new Dimension(30, 30));
	            	TestFrame test  = new TestFrame();
	            	test.setVisible(true);
	            }
	        });
	    } catch (Exception e) {
	        System.err.println("createGUI didn't successfully complete");
	    }
	}

	
	public TestFrame() {
		super();
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setLayout(new FlowLayout());
		setSize(300, 300);
		
		icon = new ImageIcon("spinnerIcon.png");
		
		Box vBox = Box.createVerticalBox();
		
		Date startDate = (new GregorianCalendar(2000, 0, 1)).getTime();
		Date endDate = (new GregorianCalendar(2015, 0, 1)).getTime();
		
		yearSpinner = new CustomJSpinner(new SpinnerDateModel(Calendar.getInstance().getTime(), startDate, endDate, Calendar.YEAR));
		//vBox.add(Box.createVerticalGlue());
		add(yearSpinner);
		//vBox.add(Box.createVerticalGlue());
		JButton b = new JButton("");
		b.setIcon(icon);
		add(b);
		
		//add(vBox, BorderLayout.CENTER);
	}
	
	private class CustomJSpinner extends JSpinner {
		
		
		public CustomJSpinner(SpinnerModel model) {
			super(model);
			setFont(DisplayApplet.customFont);
			this.updateUI();
			Component[] components = getComponents();
			for(Component c : components) {
				if(c instanceof JButton) {
					JButton button = (JButton)c;
					button.setMinimumSize(new Dimension(100,100));
					button.setMaximumSize(new Dimension(100,100));
					button.setPreferredSize(new Dimension(100,100));
				}
			}
		}
	}

}
